extends layout

block headContent
	title Next Block

block content
	+pageTitle("Next Block")

	+dismissableInfoAlert("miningTemplatePageNoteDismissed", "About Next Block...")
		.mb-2 The Next Block tool displays the output from the <b>getblocktemplate</b> command which is often used by miners for building a candidate for the next block. The transactions shown here were selected from your node's mempool and generally represent those with the highest (effective) fees.
		div These details are just a best-guess based on the current mempool and will change with each refresh.

	+pageTabs(["Details", "JSON"])

	.tab-content
		+pageTab("Details", true)
			+contentSection("Summary")
				+summaryRow(3)
					+summaryItem("Transactions")
						| #{blockTemplate.transactions.length.toLocaleString()}


					+summaryItem("Fee Rates", "Minimum / Median / Maximum fee rates for transaction expected to be included in the next block.", "sat/vB")
						if (maxFeeRate != -1)
							span.border-dotted(title="Minimum fee rate", data-bs-toggle="tooltip")
								+numWithMutedDecimals(new Decimal(minFeeRate).toDP(2).toString())
							
							span.text-muted.fw-light.mx-2 /
							
							span.border-dotted(title="Median fee rate", data-bs-toggle="tooltip")
								+numWithMutedDecimals(new Decimal(medianFeeRate).toDP(2).toString())
							
							span.text-muted.fw-light.mx-2 /
							
							span.border-dotted(title="Maximum fee rate", data-bs-toggle="tooltip")
								+numWithMutedDecimals(new Decimal(maxFeeRate).toDP(1).toString())

						else
							span -

					+summaryItem("Total Fees")
						- var subsidy = coinConfig.blockRewardFunction(blockTemplate.height, global.activeBlockchain);
						- var totalFees = new Decimal(blockTemplate.coinbasevalue).dividedBy(coinConfig.baseCurrencyUnit.multiplier).minus(subsidy);

						+valueDisplay(totalFees)

			if (true)
				+contentSection(blockTemplate.transactions.length.toLocaleString() + " Transaction" + (blockTemplate.transactions.length == 1 ? "" : "s"))
					.table-responsive
						table.table.table-borderless.table-striped.mb-0
							thead
								tr
									th.text-card-highlight.text-uppercase.fw-light #
									th.text-card-highlight.text-uppercase.fw-light ID
									th.text-end.text-card-highlight.fw-light
										span.text-uppercase Fee Rate
										small.ms-1 (sat/vB)

									th.text-end.text-card-highlight.text-uppercase.fw-light Fee
									th.text-end.text-card-highlight.fw-light
										span.text-uppercase Weight
										small.ms-1 (wu)
									//th Depends

							tbody
								each tx, txIndex in blockTemplate.transactions
									tr
										td
											small.text-muted #{(txIndex).toLocaleString()}

										td
											a(href=`./tx/${tx.txid}`) #{utils.ellipsizeMiddle(tx.txid, 16)}

										td.text-end
											| #{new Decimal(tx.fee).dividedBy(tx.weight).times(4).toDP(2)}

											if (tx.avgFeeRate)
												span.text-muted.ms-2 (
													span.border-dotted(title="Effective fee rate, including ancestor transactions", data-bs-toggle="tooltip")
														span.text-muted #{new Decimal(tx.avgFeeRate).toDP(2)}
													| )
											

										td.text-end
											+valueDisplay(new Decimal(tx.fee).dividedBy(coinConfig.baseCurrencyUnit.multiplier))

										td.text-end #{tx.weight.toLocaleString()}
										//td #{tx.depends.map(x => `#${(x - 1)}`).join(", ")}


		+pageTab("JSON")
			- var x = blockTemplate;
			- delete x.transactions;

			+contentSection("Template Details")
				pre
					code.json #{JSON.stringify(x, null, 4)}
